<?php
namespace Home\Controller;

class ToolbarController extends HomeController {
 

   public function index(){

        $this->display();
	}
   public  function address() {
       $cart=R("shopcart/usercart");
       $this->assign('usercart',$cart);
         if(!session('user_auth'))
   		{
   		 $usercart=$_SESSION['cart'];
          $this->assign('usercart',$usercart);
   	    }


   	$menu=R('index/menulist');
   	   $this->assign('categoryq', $menu);
   $m=D("member");
    $uid=$m->uid();
   if(IS_POST){

   }
   else{

    $address=M("transport");
   $list=$address->where("uid='$uid'")->select();
   $this->assign('list', $list);
    $this->meta_title = get_username().'的地址管理';

   $this->display();
   }

   }
   public  function shezhi() {

   if(IS_AJAX){$m=D("member");
    $uid=$m->uid();
   $Transport = M("transport"); // 实例化transport对象
   $data['status'] = 0;
   $Transport->where("uid='$uid'")->save($data);
   $id=$_POST["id"];
   $result=$Transport->where("uid='$uid' and id='$id'")->setField("status",1);
    if($result){
   	 $msg = "设置成功";
    $this->ajaxreturn($msg);
    }
    else{
     $msg = "设置失败";
    $this->ajaxreturn($msg);
    }
   }
   }

   // 增加地址
   public  function save() {
        $Transport = M("transport"); // 实例化transport对象
        $data['address'] = $_POST["posi"];
        $data['cellphone'] = $_POST["pho"];
   	 $data['realname'] = $_POST["rel"];
        $Member=D("member");
   	  $uid=$Member->uid();
   	  $data['uid'] = $uid;
   	  $data['status'] = 0;
         $data['time']=NOW_TIME;
   	if($Transport->add($data)){
   	 $id=$Transport->where("uid='$uid'")->limit(1)->order("id desc")->getField("id");
   	 $this->ajaxreturn($id);
   	}
   else{
    $this->ajaxreturn($data);
   }
   }
   // 删除地址
   public  function deleteAddress() {
         $Transport = M("transport"); // 实例化transport对象
         $Member=D("member");
   	  $uid=$Member->uid();
   	  $id=$_POST["id"];
   	if($Transport->where("uid='$uid' and id='$id'")->delete()){
   		 $data['msg'] = "删除成功";
   		 $data['status'] = 1;
   	 $this->ajaxreturn($data);
   	}
   else{ $data['msg'] = "删除失败";
   $data['status'] = 0;
    $this->ajaxreturn($data);
   }
   }

   public function contribution(){
        $this->display();
   }
}